package com.buaa.spinner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import java.util.List;
import java.util.Map;

import util.SpinnerAdapter;

public class MainActivity extends AppCompatActivity {
    private Spinner spinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinner=(Spinner)findViewById(R.id.spinner);
        List<Map<String,Object>> list=SpinnerAdapter.getListMap();
        SimpleAdapter simpleAdapter=new SimpleAdapter(MainActivity.this,list,R.layout.item,new String[]{"ivLogo","applicationName"},new int[]{R.id.imageview,R.id.textview});
        spinner.setAdapter(simpleAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String appName=((Map<String,Object>)spinner.getItemAtPosition(position)).get("applicationName").toString();
                setTitle(appName);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
}
